<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:dt="http://code.google.com/p/discotag/WorkFile"
>
	<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
	
	<!-- Responsible for duplicating the old discogs response //-->
	<xsl:template match="*" mode="discogs">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()" mode="discogs" />
		</xsl:copy>
	</xsl:template>
	<xsl:template match="@*|text()|comment()|processing-instruction" mode="discogs">
		<xsl:copy-of select="." />
	</xsl:template>
	
	<!-- Template for release element //-->
	<xsl:template match="/resp/release">
		<!-- Release-ID //-->
		<xsl:attribute name="discogs-id">
			<xsl:value-of select="@id" />
		</xsl:attribute>
		<!-- Title //-->
		<dt:title>
			<xsl:value-of select="title" />
		</dt:title>
		<!-- Primary Artists (under which the release got released) //-->
		<xsl:for-each select="artists/artist">
			<dt:artist type="primary">
				<xsl:if test="join != ''">
					<xsl:attribute name="join">
						<xsl:value-of select="join" />
					</xsl:attribute>
				</xsl:if>
				<xsl:value-of select="name" />
			</dt:artist>
		</xsl:for-each>
		<!-- Extra Artists (who helped out) //-->
		<xsl:for-each select="extraartists/artist">
			<dt:artist type="extra">
				<xsl:attribute name="role">
					<xsl:value-of select="role" />
				</xsl:attribute>
				<xsl:value-of select="name" />
			</dt:artist>
		</xsl:for-each>
	</xsl:template>
	
	<!-- Root template //-->
	<xsl:template match="/">
		<dt:discotag type="workfile" revision="1">
			<dt:meta>
				<dt:actions>
				</dt:actions>
			</dt:meta>
			<dt:release>
				<xsl:apply-templates match="/resp/release" />
			</dt:release>
			<dt:tracklist>
			</dt:tracklist>
			<dt:discogs>
				<xsl:apply-templates match="*" mode="discogs" />
			</dt:discogs>
		</dt:discotag>
	</xsl:template>
	
</xsl:stylesheet>